package com.angus.auth.controller;

import com.angus.api.system.model.LoginUser;
import com.angus.common.core.domain.R;
import com.angus.common.core.utils.StringUtils;
import com.angus.common.security.service.TokenService;
import org.springframework.web.bind.annotation.PostMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author liyanan
 * @date 2024/10/14 4:12 PM
 * @description
 */
public class CommonTokenController {

    @Resource
    private TokenService tokenService;

    @PostMapping("refresh")
    public R<?> refresh(HttpServletRequest request)
    {
        LoginUser loginUser = tokenService.getLoginUser(request);
        if (StringUtils.isNotNull(loginUser))
        {
            // 刷新令牌有效期
            tokenService.refreshToken(loginUser);
            return R.ok();
        }
        return R.ok();
    }

}
